package com.huawei.secure.android.common.util;

import android.text.TextUtils;
import android.util.Log;
import com.huawei.hwid.core.constants.HwAccountConstants;

public abstract class SafePrintException {
    public static void print(String str, String str2, Throwable th) {
        if (th != null) {
            Log.w(str, getStackTrace(str2, th));
        }
    }

    public static String getStackTrace(String str, Throwable th) {
        StringBuilder stringBuilder = new StringBuilder();
        if (!TextUtils.isEmpty(str)) {
            stringBuilder.append(str).append(HwAccountConstants.BLANK);
        }
        stringBuilder.append("Exception: ").append(th.getClass().getName()).append('\n');
        if (!c(th.getClass().getCanonicalName())) {
            StackTraceElement[] stackTrace = th.getStackTrace();
            if (stackTrace == null) {
                stringBuilder.append("Stack trace is NULL!").append('\n');
            } else {
                for (StackTraceElement stackTraceElement : stackTrace) {
                    stringBuilder.append(stackTraceElement.toString()).append('\n');
                }
            }
        }
        return stringBuilder.toString();
    }

    private static boolean c(String str) {
        for (CharSequence contains : new String[]{"java.io.FileNotFoundException", "java.util.jar.JarException", "java.util.MissingResourceException", "java.security.acl.NotOwnerException", "java.util.ConcurrentModificationException", "javax.naming.InsufficientResourcesException", "java.net.BindException", "java.lang.OutOfMemoryError", "java.lang.StackOverflowError", "java.sql.SQLException"}) {
            if (str.contains(contains)) {
                return true;
            }
        }
        return false;
    }
}
